package com.example.upload.controller.user;

import com.example.upload.dto.user.LoginDto;
import com.example.upload.dto.user.RegisterDto;
import com.example.upload.response.ResponseResult;
import com.example.upload.response.ResponseResultFactory;
import com.example.upload.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author lsx
 * @description: TODO
 * @date 2024年06月07日 15:36
 * @Version: 1.0
 */
@RestController
@RequestMapping("/fileStorage/user")
public class AccountController {

    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public ResponseResult register(@RequestBody @Validated RegisterDto registerDto){
        userService.lockExecution(registerDto.getTell(),()->{
            userService.register(registerDto);
        });
        return ResponseResultFactory.buildSuccessResponse();
    }

    @GetMapping("/login")
    public ResponseResult login(@RequestBody @Validated LoginDto loginDto){
        userService.login(loginDto);
        return ResponseResultFactory.buildSuccessResponse();
    }
}
